//
//  NSDictionary+RJ.m
//  Seeme
//
//  Created by Jiang on 2016/12/13.
//  Copyright © 2016年 Jiang. All rights reserved.
//

#import "NSDictionary+RJ.h"

@implementation NSDictionary (RJ)

- (void)rj_setValue:(id)value forKey:(NSString *)key {

    if (value != nil && value != NULL) {
        [self setValue:value forKey:key];
    }
}

#pragma mark 设置键值对（过滤空字符串和nil）
- (void)rj_setString:(NSString *)value forKey:(NSString *)key {
    
    if (value != nil && value != NULL && value.length > 0 && [value isKindOfClass:[NSString class]]) {
        [self setValue:value forKey:key];
    }
}

#pragma mark 字典 转 字符串
- (NSString *)rj_dictionaryToJsonStr {

    NSError *parseError = nil;

    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self options:NSJSONWritingPrettyPrinted error:&parseError];

    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}

@end
